package org.hadoop.seq;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.SequenceFileOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
public class SequenceFileOutMR extends Configured implements Tool {
    @Override
    public int run(String[] args) throws Exception {
        Configuration config = getConf();
        FileSystem fs = FileSystem.get(config);
        Path dest  = new Path("D:/a/out002");
        if(fs.exists(dest)) {
            fs.delete(dest, true);
        }
        Job job = Job.getInstance(config,"Seq");
        job.setJarByClass(getClass());
        job.setInputFormatClass(TextInputFormat.class);
        job.setOutputFormatClass(SequenceFileOutputFormat.class);
        FileInputFormat.setInputPaths(job, new Path("D:/a/a.txt"));
        FileOutputFormat.setOutputPath(job, dest);
        int code = job.waitForCompletion(true)?0:1;
        return code;
    }
    public static void main(String[] args) throws Exception {
        int code = ToolRunner.run(new SequenceFileOutMR(), args);
        System.exit(code);
    }
}